/**
 * @author Luc Yriarte
 * 
 * Licence : BSD http://www.opensource.org/licenses/bsd-license.php
 *  
 */
package physicSim;

import basicSim.Object3D;
import basicSim.Vector;
import basicSim.Vector3D;

/**
 * SolidObject : A weighted 3D Object 
 * 
 * Physics units in m / kg / s
 * Left handed geometric coordinates
 * 
 */
public class SolidObject {
	/** By default objects weight 1 kg */
	public static double DEFAULT_MASS=1;
	/** mass in kg */
	public double mass;
	/** Geometric object to draw.  */
	public Object3D object3D;
	protected Vector position;
	protected Vector velocity;
	protected Vector acceleration;
	
	/**
	 * 
	 */
	public SolidObject() {
		super();
		this.mass = DEFAULT_MASS;
		this.position=new PhysicVector();
		this.velocity=new PhysicVector();
		this.acceleration=new PhysicVector();
	}
	
	/**
	 * @param mass
	 */
	public SolidObject(double mass) {
		super();
		this.mass = mass;
		this.position=new PhysicVector();
		this.velocity=new PhysicVector();
		this.acceleration=new PhysicVector();
	}
	
	/**
	 * @param mass
	 * @param object3D
	 */
	public SolidObject(double mass, Object3D object3D) {
		super();
		this.mass = mass;
		this.object3D = object3D;
		this.position=new PhysicVector();
		this.velocity=new PhysicVector();
		this.acceleration=new PhysicVector();
	}

	public Vector getPosition() {
		return position;
	}
	public void setPosition(Vector position) {
		this.position = position;
		object3D.setPosition(new Vector3D(position).positionMatrix());
		
	}
	public Vector getVelocity() {
		return velocity;
	}
	public Vector getAcceleration() {
		return acceleration;
	}

	/**
	 * @param dt
	 */
	public SolidObject updateState(double dt) {
		velocity.addMulNumThis(acceleration, dt);
		position.addMulNumThis(velocity, dt);
		object3D.setPosition(new Vector3D(position).positionMatrix());
		return this;
	}
	
	/**
	 * @param f
	 */
	public SolidObject applyForce(Vector f) {
		acceleration.addMulNumThis(f, 1/mass);
		return this;
	}
	
}
